//
//  DYLeftDrawerVC.m
//  Run
//
//  Created by BetaTheta on 16/3/30.
//  Copyright © 2016年 BetaTheta. All rights reserved.
//

#import "DYLeftDrawerVC.h"
#import "Today_VC.h"
#import "DYMainVC.h"
#import "Record_VC.h"
#import "RunFriend_VC.h"
#import "Course_VC.h"
#import "Set_VC.h"
#import "TimeViewController.h"


@interface DYLeftDrawerVC ()<UITableViewDelegate, UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIImageView *headerBgView;
@property (nonatomic, strong) UIImageView *faceView;// 用户头像
@end

@implementation DYLeftDrawerVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    [self creatTableView];
}
- (void) creatTableView
{
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
    _tableView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleWidth;
    _tableView.dataSource = self;
    _tableView.delegate  = self;
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.backgroundView = nil;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    _tableView.bounces = NO;
    [_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    [self.view addSubview:_tableView];
    // 创建tableView的header
    self.headerBgView = [[UIImageView alloc] init];
    [_headerBgView setImage:[UIImage imageNamed:@"主视图导航图片"]];
    _headerBgView.frame = CGRectMake(0, 0, WIDTH, HEIGHT / 4);
    /**< 高斯模糊 */
    //  创建需要的毛玻璃特效类型
    UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
    //  毛玻璃view 视图
    UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
    //添加到要有毛玻璃特效的控件中
    effectView.frame = self.headerBgView.bounds;
    [_headerBgView addSubview:effectView];
    //设置模糊透明度
    effectView.alpha = 0.8;
    _headerBgView.userInteractionEnabled = YES;
    _tableView.tableHeaderView = _headerBgView;
    // 创建用户头像
    self.faceView = [[UIImageView alloc] initWithFrame:CGRectMake(WIDTH / 8, WIDTH / 8, WIDTH / 5, WIDTH / 5)];
    _faceView.image = [UIImage imageNamed:@"主视图导航图片"];
    _faceView.layer.cornerRadius = _faceView.frame.size.width / 2;
    _faceView.backgroundColor = [UIColor blackColor];
    _faceView.clipsToBounds = YES;
    // 用户交互
    _faceView.userInteractionEnabled = YES;
    [_headerBgView addSubview:_faceView];

}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 7;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.backgroundColor = [UIColor clearColor];
   
    NSArray *arr = @[@"今天", @"跑步", @"记录", @"跑友圈", @"运动教程", @"设置",@"闹钟"];
    NSArray *ImgNameArr = @[@"今天", @"跑步", @"记录", @"跑友圈", @"教程", @"设置",@"闹钟"];
    cell.textLabel.text = arr[indexPath.row];
    cell.imageView.image = [UIImage imageNamed:ImgNameArr[indexPath.row]];
    
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 50;
}
// cell触发方法->push 模块Page
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    switch (indexPath.row) {
            // 今天
        case 0:
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[Today_VC alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
            // 跑步
        case 1:
           
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[DYMainVC alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 2:
            // 记录
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[Record_VC alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 3:
            // 跑友圈
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[RunFriend_VC alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
        case 4:
            // 运动教程

//            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[DYOtherCourse_VC alloc] init]]
//                                                         animated:YES];

            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[Course_VC alloc] init]]
                                                         animated:YES];

            [self.sideMenuViewController hideMenuViewController];
            break;
        case 5:
            // 设置
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[Set_VC alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
            break;
            case 6:
            
            [self.sideMenuViewController setContentViewController:[[UINavigationController alloc] initWithRootViewController:[[TimeViewController alloc] init]]
                                                         animated:YES];
            [self.sideMenuViewController hideMenuViewController];
        
        default:
            break;
    }
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
